package com.hy.thread;

import java.util.Date;
import java.util.concurrent.*;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:测试线程池
 * <p>
 * User:Mr.Du
 * Date:2024/7/13
 * Time:19:17
 */
public class TestThreadPool {

    public static void main(String[] args) {
        testThreadPool();
    }

    public static void testThreadPool() {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 10, 60,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        threadPoolExecutor.execute(()->{
            System.out.println("线程池测试execute: " + new Date());
        });
        Future<?> submit = threadPoolExecutor.submit(() -> {
            System.out.println("线程池测试submit: " + new Date());
            return 1;
        });
        try {
            Object o = submit.get();
            System.out.println(o);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}
